﻿/*
 * @Autor: PK
 * @Date: 2022/01/25 19:56:SS
 */

using System.Collections.Generic;
using System.Collections.Immutable;

namespace ShkSimulation.core.optimization.extractor {
	
	public class ArrayCellPointGroup {
		
		private Dictionary<string, List<CellPoint>> _location;

		public Dictionary<string, List<CellPoint>> Location {
			get => _location;
			set => _location = value ?? new Dictionary<string, List<CellPoint>>();
		}
		
		public ImmutableSortedSet<string> GetSortedName() {
			return _location.Keys.ToImmutableSortedSet();
		}

		public ArrayCellPointGroup(Dictionary<string, List<CellPoint>> location) {
			this.Location = location ?? new Dictionary<string, List<CellPoint>>();
		}

		public ArrayCellPointGroup AddCellPoint(string tableKey, CellPoint point) {
			if (!Location.ContainsKey(tableKey)) {
				Location.Add(tableKey, new List<CellPoint>());
			}
			Location[tableKey].Add(point);
			return this;
		}
		
		public ArrayCellPointGroup AddCellPoints(string tableKey, List<CellPoint> points) {
			if (!Location.ContainsKey(tableKey)) {
				Location.Add(tableKey, new List<CellPoint>());
			}
			Location[tableKey].AddRange(points);
			return this;
		}
		
		public ArrayCellPointGroup RemoveTable(string tableKey) {
			if (!Location.ContainsKey(tableKey)) {
				return this;
			}
			Location.Remove(tableKey);
			return this;
		}

	}

}